const Koa = require('koa')
const static = require('koa-static')
const Router = require('koa-router')
const axios = require('axios')
const koaServerHttpProxy = require("koa-server-http-proxy");
let app = new Koa()
app.use(static(__dirname + "/static"));
let router = new Router()
    // app.use()

app.use(koaServerHttpProxy("/api", {
    target: "http://localhost:4000",
    pathRewrite: { '^/api': '' }, //pathRewrite路径重写
    changeOrigin: true
}));




router.get('/api/getdata', async ctx => {
    // axios.get('http://localhost:4000/test').then(res => {
    //     console.log(res.data);
    // })
    // ctx.body = {
    //         info: '3000端口的数据'
    //     }
    let { data } = await axios.get('http://localhost:4000/test')
    ctx.body = data
})
app.use(router.routes())
app.listen(3000)